// 集合类型练习


trait IpAddr {
    fn display(&self);
}

struct V4(String);

impl IpAddr for V4 {
    fn display(&self) {
        println!("IP V4: {:?}", self.0);
    }
}

struct V6(String);

impl IpAddr for V6 {
    fn display(&self) {
        println!("IP V6: {:?}", self.0);
    }
}


fn main() {

    test_vec();

    test_map();
}


fn test_vec() {
    let mut v = vec![1, 2, 3]; //vec! 带初始化
    for i in &mut v {
        *i *= 2;
    }
    println!("{:?}", v);

    // 特征对象实现vector存储不同类型
    let ips: Vec< Box<dyn IpAddr> > = vec![
        Box::new(V4("127.0.0.1".to_string())),
        Box::new(V6("::1".to_string())),
    ];
    for ip in ips {
        ip.display();
    }
}

fn test_map() {

}